//
//  OrderDetailController.m
//  LuCaiZhu
//
//  Created by Stella on 2018/9/25.
//
#import "OrderViewCell.h"
#import "Header.h"
#import "UIColor+NN.h"
#import "SignDetailMode.h"
#import "CKPuslichTool.h"
#import "VerifySMSController.h"
#import "HandleNetProduct.h"
#import "OrderDetailController.h"

@interface OrderDetailController (){
    NSString *bookingId;
    NSString *stepName;
}
@property (weak, nonatomic) IBOutlet UITableView *mTableView;
@property (weak, nonatomic) IBOutlet UIView *downView;
@property (strong, nonatomic)NSArray *datas;
@end

@implementation OrderDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"订单详情";
    self.mTableView.backgroundColor = [UIColor colorWithHexString:@"F4f4f4"];
    self.mTableView.estimatedRowHeight=51;
    self.mTableView.rowHeight = UITableViewAutomaticDimension;
    bookingId = _stepDic[@"BookingId"];
    stepName = _stepDic[@"StepName"];
    if ([self.stepDic[@"Status"] isEqualToString:@"完成"]) {
        self.downView.hidden = YES;
    }else{
        self.downView.hidden = NO;
    }
    [self getDetailInfo];
}

- (IBAction)cancel:(id)sender {
    
}
- (IBAction)okPress:(id)sender {
    if ([_stepDic[@"IsSMS"] isEqualToString:@"Yes"]) {
        //判断改为如果是最后一步
        VerifySMSController *vc = (VerifySMSController *)[CKPuslichTool getViewControllerFromStroyBoard:@"My" viewID:@"VerifySMSController"];
        [vc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
        [vc setModalPresentationStyle:UIModalPresentationOverFullScreen];
        vc.returnVerifyOK = ^{
            [self okok];
        };
        vc.isEmail = NO;
        
        [self presentViewController:vc animated:YES completion:nil];
    }else{
        [self okok];
    }
    
    
}

- (void)okok{
    [HandleNetProduct updateSigningStatusforBookingID:bookingId SignName:stepName Success:^(NSDictionary *data) {
        _downView.hidden = YES;
        if (self.returnChangeOK) {
            self.returnChangeOK();
        }
        [self.navigationController popViewControllerAnimated:YES];
    } Failure:^(NSString *errorInfo) {
        
    }];
}

- (void)getDetailInfo{
    [HandleNetProduct getSigningDetailforBookingID:bookingId Success:^(NSDictionary *data) {
        _datas = @[@{@"name":@"产品名称",@"content":data[@"SubProductName"]},
                   @{@"name":@"成立/开放日",@"content":data[@"PurchaseOpenDay"]},
                   @{@"name":@"交易类型",@"content":data[@"BookingType"]},
                   @{@"name":@"交易金额(万元)",@"content":data[@"Amount"]},
                   @{@"name":@"认购费(万元)",@"content":data[@"BookingFee"]},
                   @{@"name":@"合计需打款(万元)",@"content":data[@"MustAmount"]},
                   @{@"name":@"到账金额(万元)",@"content":data[@"TotalPayment"]}];
        [self.mTableView reloadData];
    } Failure:^(NSString *errorInfo) {
        
    }];
}
#pragma mark - Table view data source
//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    return UITableViewAutomaticDimension;
//}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _datas.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    OrderViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OrderViewCell"];
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = [UIColor whiteColor];
    cell.leftLa.text = _datas[indexPath.row][@"name"];
    cell.rightLa.text = _datas[indexPath.row][@"content"];
    if ([cell.leftLa.text rangeOfString:@"合计需打款"].length > 0) {
        cell.rightLa.textColor = MAIN_COLOR_Red;
    }else{
        cell.rightLa.textColor = [UIColor blackColor];
    }
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0.01f;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01f;
}



@end
